package o;

import android.os.Process;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

final class td {
    private volatile boolean ʼ;
    private final Executor ˊ;
    private final ReferenceQueue<tq<?>> ˋ;
    @VisibleForTesting
    final Map<sa, a> ˎ;
    private final boolean ˏ;
    private c ॱ;
    @Nullable
    private volatile e ॱॱ;

    @VisibleForTesting
    static final class a extends WeakReference<tq<?>> {
        @Nullable
        tx<?> ˊ;
        final sa ˏ;
        final boolean ॱ;

        a(@NonNull sa saVar, @NonNull tq<?> tqVar, @NonNull ReferenceQueue<? super tq<?>> referenceQueue, boolean z) {
            tx txVar;
            super(tqVar, referenceQueue);
            this.ˏ = (sa) aas.ˎ(saVar);
            if (tqVar.ˏ() && z) {
                txVar = (tx) aas.ˎ(tqVar.ˊ());
            } else {
                txVar = null;
            }
            this.ˊ = txVar;
            this.ॱ = tqVar.ˏ();
        }

        void ॱ() {
            this.ˊ = null;
            clear();
        }
    }

    @VisibleForTesting
    interface e {
        void ˎ();
    }

    td(boolean z) {
        this(z, Executors.newSingleThreadExecutor(new ThreadFactory() {
            public Thread newThread(@NonNull final Runnable runnable) {
                return new Thread(new Runnable(this) {
                    final /* synthetic */ AnonymousClass1 ˏ;

                    public void run() {
                        Process.setThreadPriority(10);
                        runnable.run();
                    }
                }, "glide-active-resources");
            }
        }));
    }

    @VisibleForTesting
    td(boolean z, Executor executor) {
        this.ˎ = new HashMap();
        this.ˋ = new ReferenceQueue();
        this.ˏ = z;
        this.ˊ = executor;
        executor.execute(new Runnable(this) {
            final /* synthetic */ td ˎ;

            {
                this.ˎ = r1;
            }

            public void run() {
                this.ˎ.ˊ();
            }
        });
    }

    void ˋ(c cVar) {
        synchronized (cVar) {
            synchronized (this) {
                this.ॱ = cVar;
            }
        }
    }

    synchronized void ˏ(sa saVar, tq<?> tqVar) {
        a aVar = (a) this.ˎ.put(saVar, new a(saVar, tqVar, this.ˋ, this.ˏ));
        if (aVar != null) {
            aVar.ॱ();
        }
    }

    synchronized void ˊ(sa saVar) {
        a aVar = (a) this.ˎ.remove(saVar);
        if (aVar != null) {
            aVar.ॱ();
        }
    }

    @Nullable
    synchronized tq<?> ˎ(sa saVar) {
        tq<?> tqVar;
        a aVar = (a) this.ˎ.get(saVar);
        if (aVar == null) {
            tqVar = null;
        } else {
            tqVar = (tq) aVar.get();
            if (tqVar == null) {
                ˊ(aVar);
            }
        }
        return tqVar;
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    void ˊ(@androidx.annotation.NonNull o.td.a r7) {
        /*
        r6 = this;
        monitor-enter(r6);
        r0 = r6.ˎ;	 Catch:{ all -> 0x0028 }
        r1 = r7.ˏ;	 Catch:{ all -> 0x0028 }
        r0.remove(r1);	 Catch:{ all -> 0x0028 }
        r0 = r7.ॱ;	 Catch:{ all -> 0x0028 }
        if (r0 == 0) goto L_0x0010;
    L_0x000c:
        r0 = r7.ˊ;	 Catch:{ all -> 0x0028 }
        if (r0 != 0) goto L_0x0012;
    L_0x0010:
        monitor-exit(r6);	 Catch:{ all -> 0x0028 }
    L_0x0011:
        return;
    L_0x0012:
        monitor-exit(r6);	 Catch:{ all -> 0x0028 }
        r0 = new o.tq;
        r1 = r7.ˊ;
        r2 = 1;
        r3 = 0;
        r4 = r7.ˏ;
        r5 = r6.ॱ;
        r0.<init>(r1, r2, r3, r4, r5);
        r1 = r6.ॱ;
        r2 = r7.ˏ;
        r1.ˏ(r2, r0);
        goto L_0x0011;
    L_0x0028:
        r0 = move-exception;
        monitor-exit(r6);	 Catch:{ all -> 0x0028 }
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.td.ˊ(o.td$a):void");
    }

    void ˊ() {
        while (!this.ʼ) {
            try {
                ˊ((a) this.ˋ.remove());
                e eVar = this.ॱॱ;
                if (eVar != null) {
                    eVar.ˎ();
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    }
}
